package com.atguigu.boot;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.jms.Queue;
import java.util.Date;
import java.util.UUID;

@Component
public class Queue_Produce {
    @Autowired
    private JmsMessagingTemplate template;
    @Autowired
    private Queue queue;
    //注意这里是import javax.jms.Queue;
    public void produceMsg(){
        template.convertAndSend(queue,
                "UUID:"+ UUID.randomUUID().toString().substring(0,6));
    }
    //间隔3s定投方法
    @Scheduled(fixedDelay = 3000)//单位ms
    public void produceMsgScheduled(){
        template.convertAndSend(queue, new Date().toString());
        System.out.println("成功投放1条消息！！！");
    }
}
